package com.free.event;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * <p>
 * Title: Eclipse Plugin Development
 * </p>
 * <p>
 * Description: Free download
 * </p>
 * <p>
 * mail: ganshm@gmail.com
 * </p>
 */

public class KeyListenerExample
{
    
    Display display;
    
    Shell shell;
    
    KeyListenerExample()
    {
        
        display = new Display();
        shell = new Shell(display);
        
        shell.setSize(250, 200);
        shell.setText("A KeyListener Example");
        Text text = new Text(shell, SWT.BORDER);
        text.setBounds(50, 50, 100, 20);
        
        text.addKeyListener(new KeyListener()
        {
            
            public void keyPressed(KeyEvent e)
            {
                
                System.out.println("key Pressed -" + e.character);
            }
            
            public void keyReleased(KeyEvent e)
            {
                System.out.println("key Released -" + e.character);
            }
        });
        shell.open();
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
    
    public static void main(String[] args)
    {
        new KeyListenerExample();
    }
    
}
